package avicit.bdp.dms.das.rest;

import avicit.bdp.dms.das.dto.LayerDTO;
import avicit.bdp.dms.das.service.LayerService;
import avicit.platform6.core.rest.msg.QueryRespBean;
import avicit.platform6.core.rest.msg.ResponseMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yangpf
 * 数据分层管理
 */
@RestController
@Api(tags = "数据分层Rest接口")
@RequestMapping("/api/bdp/dms/das/layer")
public class LayerRest {
    @Autowired
    private LayerService layerService;

    @ApiOperation(value = "分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "查询关键词", name = "keyWords", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "状态", name = "status", dataType = "Int", paramType = "query"),
            @ApiImplicitParam(value = "当前页", name = "pageNo", dataType = "Int", paramType = "query"),
            @ApiImplicitParam(value = "每页大小", name = "pageSize", dataType = "Int", paramType = "query")
    })
    @GetMapping(value = "/getPageList")
    public ResponseMsg<QueryRespBean<LayerDTO>> getPageList(
            @RequestParam(required = false) String keyWords,
            @RequestParam(required = false) Integer status,
            @RequestParam(defaultValue = "1") Integer pageNo,
            @RequestParam(defaultValue = "10") Integer pageSize) throws Exception {
        ResponseMsg<QueryRespBean<LayerDTO>> responseMsg = new ResponseMsg<>();

        QueryRespBean<LayerDTO> queryRespBean = layerService.getPageList(keyWords, status, pageNo, pageSize);
        responseMsg.setResponseBody(queryRespBean);
        return responseMsg;
    }

    @ApiOperation(value = "新增数据分层")
    @PostMapping("/insertLayer")
    public ResponseMsg<String> insertLayer(@RequestBody LayerDTO layerDTO) {
        ResponseMsg<String> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(layerService.insertLayer(layerDTO));
        return responseMsg;
    }

    @ApiOperation(value = "修改业务对象")
    @PutMapping("/updateLayer")
    public ResponseMsg<String> updateLayer(@RequestBody LayerDTO layerDTO) {
        ResponseMsg<String> responseMsg = new ResponseMsg<>();
        layerService.updateLayer(layerDTO);
        return responseMsg;
    }

    @ApiOperation(value = "删除业务对象")
    @ApiParam(value = "主键id", name = "id", required = true)
    @DeleteMapping
    public ResponseMsg<Boolean> deleteLayer(@RequestBody String id) {
        ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(layerService.deleteLayer(id));
        return responseMsg;
    }

    @ApiOperation(value = "通过ID查询")
    @ApiParam(value = "id", name = "id", required = true)
    @GetMapping("/{id}")
    public ResponseMsg<LayerDTO> queryById(@PathVariable String id) {
        ResponseMsg<LayerDTO> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(layerService.queryById(id));
        return responseMsg;
    }

    @ApiOperation(value = "启用/停用")
    @PostMapping("/updateStatus")
    public ResponseMsg<Boolean> updateStatus(@RequestBody LayerDTO layerDTO) {
        ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();
        layerService.updateStatus(layerDTO.getId(), layerDTO.getStatus());
        return responseMsg;
    }

    @ApiOperation(value = "查询启用状态的数据分层列表")
    @GetMapping("/selectLayerList")
    public ResponseMsg<List<LayerDTO>> selectLayerList() {
        ResponseMsg<List<LayerDTO>> responseMsg = new ResponseMsg<>();
        List<LayerDTO> list = layerService.selectLayerList();
        responseMsg.setResponseBody(list);
        return responseMsg;
    }
}
